<template>
  <div class="archives-container">
    <HomeHeader />
    
    <!-- 第一个盒子：文章日历图表 -->
    <div class="calendar-section">
      <div class="section-title">文章日历</div>
      <div class="calendar-wrapper">
        <!-- 月份标题 -->
        <div class="month-labels">
          <span v-for="month in months" :key="month">{{ month }}月</span>
        </div>
        
        <!-- 日期网格 -->
        <div class="calendar-grid">
          <!-- 星期标签 -->
          <div class="weekday-labels">
            <span>日</span>
            <span>一</span>
            <span>二</span>
            <span>三</span>
            <span>四</span>
            <span>五</span>
            <span>六</span>
          </div>
          
          <!-- 文章贡献格子 -->
          <div class="contribution-grid">
            <div 
              v-for="(count, index) in contributionData" 
              :key="index"
              class="contribution-cell"
              :class="getCellClass(count)"
              :title="`${count} posts on this day`"
            ></div>
          </div>
        </div>
        
        <!-- 贡献度说明 -->
        <div class="contribution-legend">
          <span>少</span>
          <div class="legend-cells">
            <div class="contribution-cell level-0"></div>
            <div class="contribution-cell level-1"></div>
            <div class="contribution-cell level-2"></div>
            <div class="contribution-cell level-3"></div>
            <div class="contribution-cell level-4"></div>
          </div>
          <span>多</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import HomeHeader from '@/components/home-header.vue'

const months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

// 模拟一年的文章数据
const contributionData = ref(Array(365).fill(0).map(() => Math.floor(Math.random() * 5)))

// 根据文章数量返回对应的样式类
const getCellClass = (count) => {
  if (count === 0) return 'level-0'
  if (count === 1) return 'level-1'
  if (count === 2) return 'level-2'
  if (count === 3) return 'level-3'
  return 'level-4'
}
</script>

<style scoped lang="scss">
.archives-container {
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(to bottom, #fff5f5, #fff);
}

.calendar-section {
  max-width: 1200px;
  margin: 40px auto;
  padding: 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.section-title {
  text-align: center;
  font-size: 24px;
  color: #333;
  margin-bottom: 20px;
}

.calendar-wrapper {
  padding: 20px;
}

.month-labels {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  margin-bottom: 10px;
  padding-left: 40px;
  
  span {
    font-size: 12px;
    color: #666;
    text-align: center;
  }
}

.calendar-grid {
  display: flex;
  gap: 10px;
}

.weekday-labels {
  display: flex;
  flex-direction: column;
  gap: 4px;
  
  span {
    font-size: 12px;
    color: #666;
    height: 10px;
    line-height: 10px;
  }
}

.contribution-grid {
  display: grid;
  grid-template-columns: repeat(52, 1fr);
  gap: 4px;
}

.contribution-cell {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  transition: all 0.3s ease;
  
  &:hover {
    transform: scale(1.2);
  }
  
  &.level-0 {
    background-color: #ebedf0;
  }
  
  &.level-1 {
    background-color: #9be9a8;
  }
  
  &.level-2 {
    background-color: #40c463;
  }
  
  &.level-3 {
    background-color: #30a14e;
  }
  
  &.level-4 {
    background-color: #216e39;
  }
}

.contribution-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  
  span {
    font-size: 12px;
    color: #666;
  }
  
  .legend-cells {
    display: flex;
    gap: 4px;
    
    .contribution-cell {
      cursor: default;
      
      &:hover {
        transform: none;
      }
    }
  }
}
</style>
